<?php

include_once 'connection/connection_database.php';

class Comment {
    function Insert($comment){
        $date = date("Y-m-d H:i:s");
        if(isset($comment["question_id"])){
            $sql = "INSERT INTO comment(question_id, comment_name, comment_description, comment_datetime) VALUES('{$comment["question_id"]}', '{$comment["comment_name"]}', '{$comment["comment_description"]}', '{$date}')";
        }else{
            $sql = "INSERT INTO comment(page_id, comment_name, comment_description, comment_datetime) VALUES('{$comment["page_id"]}', '{$comment["comment_name"]}', '{$comment["comment_description"]}', '{$date}')";
        }
        return mysql_query($sql) or die(mysql_error());
    }
    
    function FillByPage($page_id){
        $sql = "SELECT * FROM comment WHERE page_id='{$page_id}' and comment_status=1";
        $resutl = mysql_query($sql) or die(mysql_error());
        return $resutl;
    }
    
    function FillByQuestion($question_id){
        $sql = "SELECT * FROM comment WHERE question_id='{$question_id}' and comment_status=1";
        $resutl = mysql_query($sql) or die(mysql_error());
        return $resutl;
    }
}

?>
